package com.bootdo.backlist.service.impl;

import com.bootdo.backlist.converter.ConvertDomainUtils;
import com.bootdo.enums.ReportStatusEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.bootdo.backlist.dao.MessageDao;
import com.bootdo.backlist.domain.MessageDO;
import com.bootdo.backlist.dto.MessageDTO;
import com.bootdo.backlist.service.MessageService;
import com.bootdo.backlist.converter.ConvertDomainUtils;
import com.bootdo.common.utils.R;



@Service
public class MessageServiceImpl implements MessageService {
	@Autowired
	private MessageDao messageDao;
	
	@Override
	public MessageDTO get(Long blackId){
			MessageDO messageDO = messageDao.get(blackId);
			if (messageDO != null){
                return ConvertDomainUtils.convertObject(messageDO,MessageDTO.class);

            }
			return null;
	}
	
	@Override
	public List<MessageDTO> list(Map<String, Object> map){
		return ConvertDomainUtils.convertList(messageDao.list(map),MessageDTO.class);
	}
	
	@Override
	public int count(Map<String, Object> map){
		return messageDao.count(map);
	}
	
	@Override
	public R save(MessageDTO message){
		message.setPostStatus(ReportStatusEnum.审核中.getCode());
		message.setCreateTime(new Date());
		message.setRisk(0);
		message.setRank(99);
	    int i = messageDao.save(ConvertDomainUtils.convertObject(message,MessageDO.class));
        return R.result(i);
	}
	
	@Override
	public R update(MessageDTO message){
	    int i = messageDao.update(ConvertDomainUtils.convertObject(message,MessageDO.class));
		return R.result(i);
	}
	
	@Override
	public R remove(Integer blackId){
	    int i = messageDao.remove(blackId);
		return R.result(i);
	}
	
	@Override
	public R batchRemove(Integer[] blackIds){
	    int i = messageDao.batchRemove(blackIds);
		return R.result(i);
	}
	
}
